<template>
  <div class="app-container">

    <el-button type="primary" style="margin-bottom: 15px;" @click="send">新增</el-button>
    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label="序号" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>

      <el-table-column label="问题" align="center" prop="question" />
      <el-table-column label="答案" align="center" prop="answer" />
      <el-table-column label="创建时间" align="center" prop="createTime" />

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" style="color: red;" @click="handleDel(scope.row)">删除</el-button>
          <el-button type="text" @click="handleEdit(scope.row)">修改</el-button>

        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination :current-page.sync="queryParams.pageNum" :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="queryParams.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"
        @size-change="fetchData" @current-change="fetchData" />
    </div>
    <showInfo ref="showInfo" />
    <add ref="add" />
  </div>
</template>

<script>
import { questions, questionsDel } from '@/api/table'
import showInfo from './showInfo.vue'
import add from './add.vue'
export default {
  components: {
    showInfo,
    add
  },
  data() {
    return {
      list: null,
      listLoading: true,
      total: 0,
      queryParams: {
        'gameType': '',
        'betType': '',
        'pageNum': 1,
        'pageSize': 10,
        userId: ''
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      questions(this.queryParams).then(response => {
        this.list = response.data.records
        this.listLoading = false
        this.total = response.data.total
      })
    },
    onSubmit() {
      this.queryParams.pageNum = 1
      this.fetchData()
    },
    reset() {
      this.$refs.form.resetFields()

      this.fetchData()
    },
    send(e) {
      this.$refs.add.show(e)
    },
    handleEdit(e) {
      this.$refs.add.edit(e)
    },
    handleDel(e) {
      this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        questionsDel(e.id).then(res => {
          this.fetchData()
          this.$message({
            type: 'success',
            message: '成功!'
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        })
      })
    }

  }
}
</script>
